from flask import Blueprint, request, session
from flask_restful import Api, Resource, marshal_with
from flask_restful.reqparse import RequestParser

from webapp.config import api_utils
from webapp.config.api_utils import oper_log, check_auth
from webapp.dto_mapper import exam_page_fields
from webapp.schema import ExamSchema
from webapp.service.exam_service import ExamInfoService

wx_examinfo_app = Blueprint('wxexaminfo', __name__, url_prefix='/wxapi/exam')
wx_examinfo_api = Api(wx_examinfo_app)


parser = RequestParser()
parser.add_argument('id', location='json', type=int, trim=True, required=True)
parser.add_argument('sessionId', location='json', type=int, trim=False, required=False)
parser.add_argument('deptId', location='json', type=int, trim=False, required=False)
parser.add_argument('courseId', location='json', type=int, trim=False, required=False)
parser.add_argument('resourceId', location='json', type=int, trim=False, required=False)
parser.add_argument('teachclass', location='json', type=int, trim=False, required=False)
parser.add_argument('ename', location='json', type=int, trim=True, required=False)
parser.add_argument('start', location='json', type=str, trim=False, required=False)
parser.add_argument('end', location='json', type=str, trim=False, required=False)
parser.add_argument('totaltime', location='json', type=int, trim=False, required=False)
parser.add_argument('score', location='json', type=int, trim=False, required=False)


@wx_examinfo_api.resource("", "/")
class ExamWxInfoApi(Resource):
    @marshal_with(exam_page_fields)
    def post(self):
        data = request.get_json()
        return ExamInfoService.query_deptId_SessionId(jsonData=data)

